#pragma once

#include "wfx.h"
#include "TokenBasic.h"
#include "ErrorHandle.h"

#include <vector>

MAKE_PTR(CProductionArg);

struct production_arg_exception : virtual exception_base {};


class CProductionArg
{
public:
    static CProductionArgPtr create(int size)
    {
        return CProductionArgPtr(new CProductionArg(size));
    }

public:
    CProductionArg(int size);
    ~CProductionArg();

    void SetArg(int pos, CTokenPtr pToken);

    int size()
    {
        return m_args.size();
    }

    template<class T>
    boost::shared_ptr<T> getArg(int pos);

private:
    std::vector<CTokenPtr> m_args;
};

template<class T>
boost::shared_ptr<T>
CProductionArg::getArg( int pos )
{
    boost::shared_ptr<T> p = boost::dynamic_pointer_cast<T>(m_args[pos]);
    if (!p)
    {
        throw production_arg_exception() << error_message("dynamic_pointer_cast fail");
    }
    return p;
}